﻿Imports System.Data.SqlClient
Public Class FormCategoryEditor

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Cmd.Parameters("@CategoryName") = Me.txtName.Text
        Cmd.Parameters("@TypeId") = Me.cboName.SelectedValue
        Cmd.Parameters("@CategoryId") = Me.txtId.Text
        If txtId.Text = "" Then
            Cmd.ExecuteNonQuery("insert into Category values(@CategoryName,@TypeId,1);")
            '    txtName.Text = ""
            '    txtId.Text = ""
            '    txtName.Focus()
            '    FormCategory.loaddata()
            '    Exit Sub
        Else
            Cmd.ExecuteNonQuery("update Category set CategoryName=@CategoryName,TypeId=@TypeId where CategoryId=@CategoryId")
            ​

        End If
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub FormCategoryEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If txtId.Text <> "" Then

            Me.Text = "ទម្រង់នៃការកែប្រែក្រុមទំនិញ"
            lbl_title.Text = "កែប្រែក្រុមទំនិញ"
            Dim dt As DataTable = Cmd.ExecuteDataTable("select * from Type")
            Me.cboName.DisplayMember = "TypeName"
            Me.cboName.ValueMember = "TypeId"
            Me.cboName.DataSource = dt
        Else
            Dim dt As DataTable = Cmd.ExecuteDataTable("select * from Type")
            Me.cboName.DisplayMember = "TypeName"
            Me.cboName.ValueMember = "TypeId"
            Me.cboName.DataSource = dt
        End If
    End Sub

    Private Sub lbl_title_Click(sender As Object, e As EventArgs) Handles lbl_title.Click

    End Sub
End Class